const express = require('express');
const router = express.Router();
const { pool } = require('../config/db');

// 获取表结构
router.get('/table-structure/:tableName', async (req, res) => {
  try {
    const tableName = req.params.tableName;
    const [rows] = await pool.query(`DESCRIBE ${tableName}`);
    res.json(rows);
  } catch (error) {
    console.error(`获取表 ${req.params.tableName} 结构失败:`, error);
    res.status(500).json({ message: '服务器错误' });
  }
});

module.exports = router;